home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Personal Computer World 2009 February
/
PCWFEB09.iso
/
Software
/
Resources
/
Chat & Communication
/
Digsby build 37
/
digsby_setup.exe
/
lib
/
protocols
/
adapters.pyo
(
.txt
)
< prev
next >
Wrap
Python Compiled Bytecode
|
2008-10-13
|
5KB
|
160 lines
# Source Generated with Decompyle++
# File: in.pyo (Python 2.5)
__all__ = [
'NO_ADAPTER_NEEDED',
'DOES_NOT_SUPPORT',
'Adapter',
'minimumAdapter',
'composeAdapters',
'updateWithSimplestAdapter',
'StickyAdapter',
'AdaptationFailure',
'bindAdapter']
from types import FunctionType, ClassType, MethodType
try:
PendingDeprecationWarning
except NameError:
class PendingDeprecationWarning(Warning):
pass
class AdaptationFailure(NotImplementedError, TypeError):
pass
def NO_ADAPTER_NEEDED(obj, protocol = None):
return obj
def DOES_NOT_SUPPORT(obj, protocol = None):
pass
try:
from _speedups import NO_ADAPTER_NEEDED, DOES_NOT_SUPPORT
except ImportError:
pass
class Adapter(object):
def __init__(self, ob):
self.subject = ob
class StickyAdapter(object):
attachForProtocols = ()
def __init__(self, ob):
self.subject = ob
provides = list(self.attachForProtocols)
declareAdapter = declareAdapter
import protocols.api
(declareAdapter,)((lambda s: self), provides, forObjects = [
ob])
def minimumAdapter(a1, a2, d1 = 0, d2 = 0):
if d1 < d2:
return a1
elif d2 < d1:
return a2
if getattr(a1, '__unbound_adapter__', a1) is getattr(a2, '__unbound_adapter__', a2):
return a1
a1ct = getattr(a1, '__adapterCount__', 1)
a2ct = getattr(a2, '__adapterCount__', 1)
if a1ct < a2ct:
return a1
elif a2ct < a1ct:
return a2
if a1 is NO_ADAPTER_NEEDED or a2 is DOES_NOT_SUPPORT:
return a1
if a1 is DOES_NOT_SUPPORT or a2 is NO_ADAPTER_NEEDED:
return a2
raise TypeError('Ambiguous adapter choice', a1, a2, d1, d2)
def composeAdapters(baseAdapter, baseProtocol, extendingAdapter):
if baseAdapter is DOES_NOT_SUPPORT or extendingAdapter is DOES_NOT_SUPPORT:
return DOES_NOT_SUPPORT
if baseAdapter is NO_ADAPTER_NEEDED:
return extendingAdapter
if extendingAdapter is NO_ADAPTER_NEEDED:
return baseAdapter
def newAdapter(ob):
ob = baseAdapter(ob)
if ob is not None:
return extendingAdapter(ob)
newAdapter.__adapterCount__ = getattr(extendingAdapter, '__adapterCount__', 1) + getattr(baseAdapter, '__adapterCount__', 1)
return newAdapter
def bindAdapter(adapter, proto):
maxargs = 2
f = adapter
tries = 10
while not isinstance(f, FunctionType) and tries:
if isinstance(f, MethodType):
maxargs += (f.im_self is not None)
f = f.im_func
tries = 10
continue
if isinstance(f, (ClassType, type)):
maxargs += 1
f = f.__init__
tries -= 1
continue
f = f.__call__
tries -= 1
if isinstance(f, FunctionType):
getargspec = getargspec
import inspect
(args, varargs, varkw, defaults) = getargspec(f)
if defaults:
args = args[:-len(defaults)]
if len(args) >= maxargs:
newAdapter = lambda ob: adapter(ob, proto)
newAdapter.__adapterCount__ = getattr(adapter, '__adapterCount__', 1)
newAdapter.__unbound_adapter__ = adapter
warn = warn
import warnings
warn('Adapter %r to protocol %r needs multiple arguments' % (adapter, proto), PendingDeprecationWarning, 6)
return newAdapter
return adapter
def updateWithSimplestAdapter(mapping, key, adapter, depth):
new = adapter
old = mapping.get(key)
if old is not None:
(old, oldDepth) = old
new = minimumAdapter(old, adapter, oldDepth, depth)
if old is new and depth >= oldDepth:
return False
mapping[key] = (new, depth)
return True